<template>
  <div>
    <el-form :model="listform">
      <el-form-item label="所属学科" :label-width="formLabelWidth">
        <el-select placeholder="请选择" v-model="listform.subjectID">
          <el-option
            v-for="item in stadyList"
            :key="item.id"
            :label="item.subjectName"
            :value="item.subjectID"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目录名称" :label-width="formLabelWidth">
        <el-input
          v-model="listform.directoryName"
          style="width: 224px"
          placeholder="请输入目录名称"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="SubHandler">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { add, list, update } from '@/api/hmmm/directorys.js'
export default {
  data () {
    return {
      list: [],
      dialogFormVisible: false,
      formLabelWidth: '120px',
      listform: {},
      stadyList: []
    }
  },
  props: {
    listHandler: {
      typeof: Function
    },
    checkvalue: {
      typeof: Boolean
    }
  },
  created () {
    this.loadlist()
  },
  methods: {
    async loadlist () {
      const res = await list()
      this.stadyList = res.data.items
    },
    async SubHandler () {
      console.log(this.checkvalue)
      if (this.checkvalue) {
        await add({
          id: null,
          subjectID: this.listform.subjectID,
          directoryName: this.listform.directoryName
        })
        this.$emit('success')
      } else {
        await update({
          id: this.listform.id,
          subjectID: this.listform.subjectID,
          directoryName: this.listform.directoryName
        })
        this.$emit('success')
      }
    }
  }
}
</script>

<style scoped lang="scss">
.dialog-footer {
  padding-left: 120px;
}
</style>
